<%--
  Created by IntelliJ IDEA.
  User: bin.liu
  Date: 2018/12/5
  Time: 11:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<jsp:include page="/pages/sysIndex/default.jsp"/>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>

<div class="main-content">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">
                <i class="fa icon-trophy"></i> 维修单管理
            </div>
            <div class="box-tools pull-right">
                <a href="#" class="btn btn-default" id="btnSearch" title="查询"><i class="fa fa-filter"></i> 查询</a>
                <a href="javascript:;" onclick="downloadData()" class="btn btn-default btnTool" title="导出"><i class="fa fa-download"></i> 导出</a>
            </div>
        </div>

        <div class="box-body">
            <form id="searchForm" action="<c:url value="/web/wuhan/automaticRepair/listJson.action"/>" method="post"
                  class="form-inline hide" data-page-no="1" data-page-size="20" data-order-by="">
                <input type="hidden" id="repairSource" name="repairSource" value="WUHAN_GENERAL">
                <div class="form-group">
                    <label class="control-label">报修编号：</label>
                    <div class="control-inline">
                        <input type="text" id="reportCode" name="reportCode" value="" maxlength="64"  style="width: 200px"
                               class="form-control">
                    </div>
                </div>

                <div class="form-group">
                    <label class="control-label">工单状态：</label>
                    <div class="control-inline" style="width:150px">
                        <select id="orderStatus" name="orderStatus" class="form-control" >
                            <option value="" selected>&nbsp;全部&nbsp;&nbsp;&nbsp;</option>
                            <option value="WAIT_TAKING">&nbsp;待接单&nbsp;</option>
                            <option value="WAIT_PRESENCE">&nbsp;待到场&nbsp;</option>
                            <option value="WAIT_CONFIRM_FAULT">&nbsp;待确认故障&nbsp;</option>
                            <option value="UNFINISHED">&nbsp;待完成&nbsp;</option>
                            <option value="IN_AUDITING">&nbsp;审批中&nbsp;</option>
                            <option value="COMPLETED">&nbsp;已完成&nbsp;</option>
                        </select>
                    </div>
                </div>

                <div class="form-group">
                    <button type="submit" class="btn btn-primary btn-sm">查询</button>
                    <button type="reset" class="btn btn-default btn-sm">重置</button>
                </div>
            </form>

            <div style="overflow-x:auto">
                <table id="dataGrid"></table>
            </div>
            <div id="dataGridPage"></div>
        </div>
    </div>
</div>
<script>
    var selectIds = [];
    $('#dataGrid').dataGrid({
        shrinkToFit: false,
        autoScroll: true,
        searchForm: $("#searchForm"),
        columnModel: [
            {header: '报修编号', name: 'reportCode', index: 'reportCode', width: 250, align: "center"},
            {header: '工单状态', name: 'orderStatus', index: 'orderStatus', width: 150, align: "center", sortable: false},
            {header: '是否巡检范围', name: 'inRoutingScopeName', index: 'inRoutingScopeName', width: 150, align: "center", sortable: false},
            {header: '报修等级', name: 'reportLevel', index: 'reportLevel', width: 100, align: "center"},
            {header: '接单人', name: 'receiveUserName', index: 'receiveUserName', width: 100, align: "center",sortable: false},
            {header: '所属企业', name: 'enterpriseName', index: 'enterpriseName', width: 150, align: "center",sortable: false},
            {header: '报修时间', name: 'createDate', index: 'createDate', width: 200, align: "center"},
            {
                header: '操作',
                name: 'actions',
                width: 200,
                sortable: false,
                title: false,
                formatter: function (val, obj, row, act) {
                    var a = '<a  class="btn btn-default btn-xs btnList" onclick="log(' + row.id + ')" title="日志"><i class="fa fa-file-text-o"></i>日志</a>&nbsp;';
                    a += '<a class="btn btn-default btn-xs btnList" onclick="detail(' + row.id + ')" title="详情"><i class="fa fa-pencil">详情</i></a>';
                    return a;
                }
            }
        ],
        ajaxSuccess: function (data) {

        },
    });


    function editRepairOrder(id) {

        vLayuiUtil.openLayerWindow('wRepairOrder', '<c:url value="/web/admin/repairOrder/editPage.action?id="/>' + id, '编辑', ['80%', '95%'])
    }

    function detail(id) {
        vLayuiUtil.openLayerWindow('wRepairOrderDetail', '<c:url value="/web/admin/repairOrder/detail.action?id="/>' + id, '详情', ['80%', '95%'])
    }

    function log(id) {
        vLayuiUtil.openLayerWindow('wRepairOrderLog', '<c:url value="/web/admin/repairOrder/logPage.action?id="/>' + id, '日志', ['50%', '50%'])
    }

    function submitRemove(id) {
        $.ajax({
            type: 'post',
            url: "<c:url value="/web/admin/repairOrder/delete.action" />",
            data: {"id": id},
            dataType: 'json',
            async: false,
            success: function (data) {
                js.showMessage(data.msg);
                $('#dataGrid').dataGrid('refresh');
            },
            error: function () {
                js.showMessage("出错了，请联系管理员");
            }
        });
    }

    //指定岗位和人员 type:0人员，1：岗位
    function assign(type) {
        var ids = $("#dataGrid").jqGrid("getGridParam", "selarrrow");
        if (ids.length == 0) {
            js.showMessage("请选择要派单的维修单");
            return false;
        }
        if (ids.length > 1) {
            js.showMessage("只能选择一条维修单进行派单");
            return false;
        }
        if (type == 0) {
            vLayuiUtil.openLayerIframMaxWindow('wAssignUser', '<c:url value="/web/admin/repairOrder/assignUser.action?repairOrderId="/>' + ids, '指定接单人')
        }
        if (type == 1) {
            vLayuiUtil.openLayerIframMaxWindow('wAssignPosition', '<c:url value="/web/admin/repairOrder/assignPosition.action?repairOrderId="/>' + ids, '指定岗位')
        }

    }


    function  downloadData() {
        var reportCode=$('#reportCode').val( );
        var orderStatus=$('#orderStatus').val( );
        window.location.href = encodeURI(encodeURI('<c:url value="/web/wuhan/automaticRepair/exportOrder.action" />?reportCode='+reportCode + '&orderStatus='+orderStatus));
    }

</script>
